<template>
  <div class="login-bg">
    <div class="login-container">
      <div class="form-title">登录</div>
      <el-form :model="form" label-width="auto" size="large">
        <el-form-item>
          <el-input
            v-model="form.account"
            placeholder="账号"
            prefix-icon="User"
          />
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="form.password"
            type="password"
            placeholder="密码"
            prefix-icon="Lock"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="doLogin" style="width: 100%"
            >登录</el-button
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script setup>
import { reactive } from "vue";
import axios from "axios";
import { ElMessage } from "element-plus";
import { useRoute, useRouter } from "vue-router";

const router = useRouter();

const form = reactive({
  account: "15615490741",
  password: "0741",
});

const doLogin = () => {
  if (form.name == "") {
    ElMessage.error("账号不能为空");
    return;
  }
  if (form.password == "") {
    ElMessage.error("密码不能为空");
    return;
  }
  axios({
    method: "post",
    url: "http://oa.web.sdbaizhi.com/api/oa/Login/webLogin",
    data: form,
  })
    .then((res) => {
      if (res.data.code == 0) {
        ElMessage.error(res.data.msg);
      } else {
        localStorage.setItem("token", res.data.data.token);
        ElMessage.success(res.data.msg);
        setTimeout(function () {
          router.replace({ path: "/about" });
        }, 1500);
      }
    })
    .catch((err) => {
      // console.log(err)
      ElMessage.error(err.message);
    });
};
</script>

<style lang="scss" scoped>
.login-bg{
  background-color:rgba(0,0,255,0.2);
  background-size: cover;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  .form-title {
  font-size: 24px;
  margin-bottom: 40px;
  font-weight: bold;
}
.login-container {
  width: 400px;
  margin: 100px auto;
  padding: 40px;
  border-radius: 10px;
}
}
</style>
